import * as constants  from './constants';
import  axios from 'axios';
const getHomedata = (data) => ({
    type:constants.HOME_CHANGE_DATA,
    topicList:data.data.topicList,
    articleList:data.data.articleList,
    recommendList:data.data.recommendList,
});

const  addHomeList = (data,nextPage) => ({
    type:constants.ADD_HOME_DATA,
    data,

});

export const getHomeDateList = () =>{
   return (dispath) => {
     axios.get('/api/home.json').then((res) => {
       const data = res.data;
        dispath(getHomedata(data));
     }).catch((error) => {
       console.log(error);
     });

   }
};


export const getMoreDateList = (page) =>{


 return (dispatch) =>{
   axios.get('/api/homeList.json?page='+ page).then((res) =>{
   const data = res.data;
   dispatch(addHomeList(data.data,page + 1));
   }).catch((err) => {

     console.log(err);
   });

 }

};


export const toggleTopShow = (show) => ({
  type:constants.HOME_LISTENER_SCROLL_TOP,
  show
});
